import 'package:bubbles/app/main/main_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../theme/color_palettes.dart';

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  @override
  Widget build(BuildContext context) {
    final logic = Get.find<MainController>();
    return Obx(() => Scaffold(
          body: PageView(
            controller: logic.pageController,
            physics: const NeverScrollableScrollPhysics(),
            children: logic.navPages,
          ),
          backgroundColor: const Color(0xFFEEEEEE),
          floatingActionButtonLocation:
              FloatingActionButtonLocation.miniCenterDocked,
          //要实现中间的按钮凸起效果，这行起作用
          bottomNavigationBar: BottomNavigationBar(
            iconSize: 16.sp,
            selectedFontSize: 13.sp,
            unselectedFontSize: 13.sp,
            elevation: 8.0,
            backgroundColor: (logic.index.value != 1)
                ? ColorPalettes.instance.background
                : Colors.black,
            type: BottomNavigationBarType.fixed,
            currentIndex: logic.index.value,
            fixedColor: ColorPalettes.instance.primary,
            unselectedItemColor: ColorPalettes.instance.secondText,
            items: logic.bottomNavigationBarItems,
            onTap: (int index) {
              logic.navigate(index);
            },
          ),
        ));
  }
}
